package com.ruoyi.web.controller.stock;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.stock.domain.StockZhaBoard;
import com.ruoyi.stock.service.IStockZhaBoardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 涨停炸板个股Controller
 *
 * @author ruoyi
 * @date 2025-08-05
 */
@RestController
@RequestMapping("/stock/explode")
public class StockZhaBoardController extends BaseController {
    @Autowired
    private IStockZhaBoardService stockZhaBoardService;

    /**
     * 查询涨停炸板个股列表
     */
    @GetMapping("/list")
    public TableDataInfo list(StockZhaBoard stockZhaBoard) {
        startPage();
        List<StockZhaBoard> list = stockZhaBoardService.selectStockZhaBoardList(stockZhaBoard);
        return getDataTable(list);
    }

    /**
     * 导出涨停炸板个股列表
     */
    @Log(title = "涨停炸板个股", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StockZhaBoard stockZhaBoard) {
        List<StockZhaBoard> list = stockZhaBoardService.selectStockZhaBoardList(stockZhaBoard);
        ExcelUtil<StockZhaBoard> util = new ExcelUtil<StockZhaBoard>(StockZhaBoard.class);
        util.exportExcel(response, list, "涨停炸板个股数据");
    }

    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<StockZhaBoard> util = new ExcelUtil<StockZhaBoard>(StockZhaBoard.class);
        List<StockZhaBoard> list = util.importExcel(file.getInputStream());
        return stockZhaBoardService.importData(list, updateSupport);
    }

    /**
     * 获取涨停炸板个股详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(stockZhaBoardService.selectStockZhaBoardById(id));
    }

    /**
     * 新增涨停炸板个股
     */
    @Log(title = "涨停炸板个股", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StockZhaBoard stockZhaBoard) {
        return toAjax(stockZhaBoardService.insertStockZhaBoard(stockZhaBoard));
    }

    /**
     * 修改涨停炸板个股
     */
    @Log(title = "涨停炸板个股", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockZhaBoard stockZhaBoard) {
        return toAjax(stockZhaBoardService.updateStockZhaBoard(stockZhaBoard));
    }

    /**
     * 删除涨停炸板个股
     */
    @Log(title = "涨停炸板个股", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(stockZhaBoardService.deleteStockZhaBoardByIds(ids));
    }
}
